package com.pkk.penguin.components.validator.annotation.constraint;

import com.pkk.components.util.enums.DateTypeEnum;
import com.pkk.penguin.components.validator.annotation.DateType;
import com.pkk.penguin.components.validator.util.RegularValidatorUtil;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import lombok.extern.slf4j.Slf4j;


/**
 * @description: 时间类型验证
 * @author: luffy
 * @create: 2018-07-20 15:23
 **/
@Slf4j
public class DateTypeValidator implements ConstraintValidator<DateType, String> {

  private DateTypeEnum formatUnit;

  @Override
  public void initialize(DateType interf) {
    this.formatUnit = interf.formatUnit();
  }

  /**
   * @Description:
   * @Param: [field, cxt]
   * @Return: boolean
   * @Author: luffy
   * @Date: 2018/7/21 11:15
   **/
  @Override
  public boolean isValid(String field, ConstraintValidatorContext cxt) {
    return RegularValidatorUtil.isValid(formatUnit, field);
  }
}
